Socket
Socket
Sign inDemoInstall

recursive-readdir

Package Overview
Dependencies
Maintainers
2
Versions
16
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

recursive-readdir

Get an array of all files in a directory and subdirectories.


Version published
Weekly downloads
4.4M
decreased by-17.69%
Maintainers
2
Weekly downloads
 
Created

What is recursive-readdir?

The recursive-readdir npm package is used to recursively read directories and list all files within them. It can be particularly useful for tasks such as file system traversal, searching for specific file types, and performing operations on a large number of files within nested directories.

What are recursive-readdir's main functionalities?

Basic Usage

This feature allows you to list all files in a directory and its subdirectories. The code sample demonstrates how to use the package to read all files in a specified directory.

const recursive = require('recursive-readdir');

recursive('path/to/directory', (err, files) => {
  if (err) {
    console.error(err);
  } else {
    console.log(files);
  }
});

Filtering Files

This feature allows you to filter out certain files or directories. The code sample demonstrates how to ignore the 'node_modules' directory while listing all other files.

const recursive = require('recursive-readdir');

const ignoreFunc = (file, stats) => {
  return stats.isDirectory() && file === 'node_modules';
};

recursive('path/to/directory', [ignoreFunc], (err, files) => {
  if (err) {
    console.error(err);
  } else {
    console.log(files);
  }
});

Using Promises

This feature allows you to use promises instead of callbacks for better readability and error handling. The code sample demonstrates how to use promises to list all files in a specified directory.

const recursive = require('recursive-readdir');

recursive('path/to/directory')
  .then(files => {
    console.log(files);
  })
  .catch(err => {
    console.error(err);
  });

Other packages similar to recursive-readdir

Keywords

FAQs

Package last updated on 25 Oct 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc